package com.quan.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quan.admin.entity.SysUserRole;
import com.quan.admin.mapper.SysUserRoleMapper;
import com.quan.admin.service.SysUserRoleService;
import com.quan.commons.core.biz.support.MyBaseServiceImpl;
import com.quan.commons.core.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;


@Service
public class SysUserRoleServiceImpl extends MyBaseServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {

    @Autowired
	private SysUserRoleMapper mapper;

	@Override
    public IPage<SysUserRole> selectMyPage(PageUtils pageUtils, SysUserRole entity) {
        Page<SysUserRole> page = new Page<SysUserRole>(pageUtils.getPage(), pageUtils.getLimit());

        // 排序
        super.handleSort(page, pageUtils);

        return this.mapper.selectMyPage(page, entity);
    }

    @Override
    public void deleteByUserId(Serializable userId) {
        QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
        queryWrapper.eq("user_id", userId);
        super.remove(queryWrapper) ;
    }

    @Override
    public List<SysUserRole> getRolesByUserId(Serializable userId) {
        QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
        queryWrapper.eq("user_id", userId);
        return super.list(queryWrapper);
    }

}